<template>
	<y-popup ref="morePopup" mode="bottom" round='16px'>
		<view class='text-center fs-15 round-top-10 '>
			<view class="wa  py-8 border-bottom-f1 " @click="rename">重命名</view>
			<view class="wa  py-8 border-bottom-f1  " @click="del">删除</view>
			<view class="bg-white round-8 py-8 text-center text-red wa" @click="morePopup.close()">取消</view>
		</view>
	</y-popup>
</template>

<script setup>
	import { ref } from 'vue';
	import { $tool } from "@/utils";
	import { editWorksName, delWorks } from '@/api/works.js'
	import { editSceneName, delScene } from '@/api/scene.js'
	import { editVoiceName, delVoice } from '@/api/voice.js'
	
	const emit = defineEmits(['success'])
	const props=defineProps({
		type: {
			type: [String, Number],
			default: 1
		},
		id:{
			type:Number,
			default:0
		}
	})
	const morePopup = ref()
	
	const rename = () => {
		uni.showModal({
			title: '修改名称',
			editable: true,
			placeholderText: '请输入新的名称',
			success(res) {
				if (res.confirm) {
					renameX({ title: res.content, id: props.id })
				}
			}
		})
	}
	
	const renameX = async (data) => {
		if (props.type == 1) {
			await editWorksName(data)
		}
		if (props.type == 2) {
			await editSceneName(data)
		}
		
		if(props.type==3){
			await editVoiceName(data)
		}
	
		$tool.toast('修改成功');
		morePopup.value.close()
		emit('success')
	}
	
	
	
	const del = () => {
		uni.showModal({
			title: '确认删除',
			content: "确认删除？删除后无法恢复！",
			success(res) {
				if (res.confirm) {
					delX({ id: props.id })
				}
			}
		})
	}
	
	const delX = async (data) => {
		if (props.type == 1) {
			await delWorks(data)
		}
		if (props.type == 2) {
			await delScene(data)
		}
		
		if(props.type==3){
			await delVoice(data)
		}
	
		$tool.toast('删除成功');
		morePopup.value.close()
		emit('success')
	}
	const open=()=>{
		morePopup.value.open()
	}
	defineExpose({open})
</script>

<style>
</style>